﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using ARS.Control.Custom.SelectLinkage.Attributes;

namespace ARS.DataBase.ControlCustom.Custom
{
    public class DbSelectLinkage
    {
        public SelectLinkage GetModel(ref string userId)
        {
            SelectLinkage model = new SelectLinkage();

            DataBase.Provider.IDbProvider dbProvider = DataBase.Provider.DbProvider.GetInstance();
            DbDataReader dr = dbProvider.ExecuteReader("select * from ARS_SelectLinkage where Users_Id=" + userId.ToString());
            if (dr.Read())
            {
                model.UserId = Convert.ToInt32(dr["Users_Id"]);
                model.DataTextFieldList = Convert.ToString(dr["DataTextFieldList"]);
                model.DataValueFieldList = Convert.ToString(dr["DataValueFieldList"]);
                model.ParentNameFieldList = Convert.ToString(dr["ParentNameFieldList"]);
                model.DbSelectSLList = Convert.ToString(dr["DbSelectSLList"]);
                model.FirstOptionValueList = Convert.ToString(dr["FirstOptionValueList"]);
                model.FirstOptionTextList = Convert.ToString(dr["FirstOptionTextList"]);
                //model. = Convert.ToString(dr[""]);
            }
            dr.Close();
            return model;
        }

        public SelectLinkage GetModel(int userId)
        {
            string id = userId.ToString();
            return GetModel(ref id);
        }
    }
}
